<!-- 内容部分 -->
<div id="container">
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-lg4 layui-col-md-offset4">
                <!-- 登录表单 -->
                <div class="login">
                    
                    <h5 style="padding-bottom:0.6em;color:#FFFFFF;"><span style="color: red;">*</span> 当前用户名: </h5>
                    <div class="layui-form-item">
                        <input id="username" type="text" required lay-verify="required" autocomplete="off"
                            class="layui-input" name="username">
                    </div>
                    <h5 style="padding-bottom:0.6em;color:#FFFFFF;"><span style="color: red;">*</span> 旧密码: </h5>
                    <div class="layui-form-item">
                        <input id="old_password" type="password" name="old_password" required lay-verify="required"
                            autocomplete="off" class="layui-input">
                    </div>
                    <h5 style="padding-bottom:0.6em;color:#FFFFFF;"><span style="color: red;">*</span> 新密码: </h5>
                    <div class="layui-form-item">
                        <input id="new_password" type="password" name="new_password" required lay-verify="required"
                            autocomplete="off" class="layui-input">
                    </div>
                    <h5 style="padding-bottom:0.6em;color:#FFFFFF;"></h5>
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="resetpass()">提交</button>
                    </div>
                </div>
                <!-- 登录表单END -->
            </div>
        </div>
    </div>
</div>
<!-- 内容部分end -->

<script>
    $('#username').val(localStorage.getItem('username'));

    //重置密码
    function resetpass() {
        var password1 = $("#old_password").val();
        var password2 = $("#new_password").val();
        var username = $('#username').val();
        if (!password1 || !password2 || !username) {
            layer.msg('带 * 的为必填选项', {time: 1000, icon: 2, anim: 6});
            return false;
        }

        $.ajax({
            url: window.config.api_url + 'api/resetpassword',
            method: 'post',
            data: { username: username, new_password: password2, old_password: password1 },
            dataType: 'json',
            processData: true,
            cache: false,
            headers: { token: window.config.token, rtime: window.func.getTime() },
            success: function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg, { time: 1000, icon: 1 }, function () {
                        localStorage.clear();
                        window.location.href = './index.html';
                    });
                    return false;
                } else {
                    layer.msg(res.msg, { time: 1000, icon: 1 });
                    return false;
                }
            },
            fail: function () {
                window.func.error();
            }
        });
    }
</script>